<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.text.*,java.util.*,kines.ct.*"%>
<%@ page import="java.text.SimpleDateFormat, java.util.Date,java.util.*"%>
<%@ include file="../Connections/ConsorcioSQL7.jsp" %>
<%@include file="../utils/validarSession.jsp" %>
<%
	//formatea las variables para compararlas bien
	NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
	nf.setMinimumFractionDigits(2);
	nf.setMaximumFractionDigits(2);
	
	//Formatear Fechas
	SimpleDateFormat df = new SimpleDateFormat( "MMMM yyyy" );
	SimpleDateFormat dfYear = new SimpleDateFormat( "yyyy" );
	SimpleDateFormat dfMonth = new SimpleDateFormat( "MMMM" );
	
	String Siglas = (String) request.getParameter("cvedesarrollo");

	int anio = request.getParameter("anio")!=null?Integer.parseInt( request.getParameter("anio") ):Calendar.getInstance( ).get(Calendar.YEAR );

	String str_importe_values = "";
	String str_anios_labels = "";
	String str_importe_meses_values  = "";
	String str_meses_labels = "";
	
%>
<%
SimpleDateFormat dateformat= new SimpleDateFormat("yyyy-MM-dd",Locale.US);
Date Today = new Date();
String Fecha = dateformat.format(Today);
%>
<HTML>
<HEAD>
<TITLE>Proyectado Concentrado</TITLE>
<META HTTP-EQUIV="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT">
<link rel="stylesheet" type="text/css" href="../css/arastyle.css">
<style type="text/css">
<!--
.rowEven{
	background: #EFE0CF;
}

.rowOdd{
	background: #F5F0D4;
}
.style3 {
	color: #000000;
	font-family: tahoma;
}
.style4 {color: #FFFFFF}
.style5 {
	font-size: 14px;
	font-weight: bold;
}
.style7 {
	color: #CCCCCC;
	font-size: 14;
	font-weight: bold;
}
.style16 {
	font-family: tahoma;
	font-weight: bold;
	font-size: 11px;
}
.style19 {font-family: tahoma; font-size: 11px; }
.style21 {font-size: 14px}
-->
</style>
<SCRIPT language=JavaScript src="../utils/menu/milonic_src.js" type=text/javascript></SCRIPT>	
<script	language=JavaScript>
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=../utils/menu/mmenuns4.js><\/scr"+"ipt>");		
  else _d.write("<scr"+"ipt language=JavaScript src=../utils/menu/mmenudom.js><\/scr"+"ipt>"); 
</script>
<%@ include file="../utils/menu/menu_data_inside.jsp" %>
</HEAD>
<BODY class="fondo" onLoad="location.href='#inicio'">
<FORM METHOD=post ACTION="flujo_efectivo.jsp" NAME="_ConcentradoFlujo">
<%
Driver DriverRs = (Driver)Class.forName(DRIVER_SQL7).newInstance();
Connection ConnRs = DriverManager.getConnection(URLSTRING_SQL7,USERNAME_SQL7,PASSWORD_SQL7);
String query = "";
Statement StatementRs = null;
ResultSet Rsquery = null;
query += "SELECT nombreDesarrollo,Coto "+
		 " FROM desarrollos"+
		      " LEFT JOIN lotes ON lotes.iddesarrollo = desarrollos.iddesarrollo"+
		 " WHERE desarrollos.idDesarrollo='"+Siglas+"' ";
//out.println("<br>QUERY " + query);

StatementRs = ConnRs.createStatement();
Rsquery = StatementRs.executeQuery(query);

String NOMBRE = "";
int Cotos = 0;
 if (Rsquery!=null && Rsquery.next()) {
		NOMBRE = Rsquery.getString("nombreDesarrollo");
		//out.println("<br>NOMBRE" + NOMBRE);
		}
ConnRs.close();
%>
<%
ConnRs = DriverManager.getConnection(URLSTRING_SQL7,USERNAME_SQL7,PASSWORD_SQL7);
query = "exec REPORTE_FLUJO_EFECTIVO '"+Siglas+"', "+anio;
StatementRs = ConnRs.createStatement( );
Rsquery = StatementRs.executeQuery( query );
%>
  <table width="70%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr bgcolor=#663300>
    <td colspan="4"><div align="center" class="style3"><span class="style4"><span class="style5">REPORTE DE FLUJO DE EFECTIVO </span><br>
          <span class="style7"><%=NOMBRE.toUpperCase()%> </span></span></div></td>
    </tr>
  <tr bgcolor="#CCCCCC">
    <td width="33%" height="26"><div align="right" class="style16">Desarrollo:</div></td>
    <td colspan="2"><span class="style19"><a name="inicio"></a>&nbsp;
        <select name="cvedesarrollo" class="textfields" <%out.print(!session.getAttribute("Nivel_Acceso").equals("17") && !session.getAttribute("Nivel_Acceso").equals("18")?"":"disabled");%>>
				    <%=Development.getHtmlCombo( Siglas )%>
	    </select>
        <%
		if( session.getAttribute("Nivel_Acceso").equals("17") || session.getAttribute("Nivel_Acceso").equals("18") ){
			out.println("<input type=\"hidden\" name=\"cvedesarrollo\" value=\""+Siglas+"\">");
		}
		%>
    </span></td>
    <td width="32%" rowspan="2" valign="top"><div align="right" class="style19"><img src="../images/transparent.gif" border="0" name="ReportesInsideImg" id="ReportesInsideImg"><a href="javascript:popup('ReportesInside','ReportesInsideImg')" onMouseOut="popdown()"><strong>OTROS REPORTES</strong></a></div></td>
  </tr>
  <tr bgcolor="#CCCCCC">
    <td height="26"><div align="right"><strong>A&ntilde;o:</strong></div></td>
    <td width="21%">&nbsp;<select class="textfields" name="anio" id="anio">
                      <%for (int xy = 1998; xy <= 2050; xy++) {%>
                      <option <%=(xy==anio?"selected":"")%> value="<%=xy%>"><%=xy%></option>
                      <%}%>
                    </select></td>
    <td width="14%"><input name="Submit" type="submit" class="boton" value="Aceptar"></td>
  </tr>
</table>
<br>
<table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td width="50%" rowspan="2" align="center" valign="top"><table width="100%"  border="0" cellpadding="0" cellspacing="0">
      <tr  bgcolor=#663300>
        <td width="30%" class="style4"><div align="center" class="style21">Fecha</div></td>
        <td width="35%" class="style4"><div align="right" class="style21">Ingreso</div></td>
        <td width="35%" class="style4"><div align="right" class="style21">Acumulado</div></td>
      </tr>
      <%
  Date dtmp;
  boolean rowEven = true;
  while( Rsquery.next( ) ){
  	dtmp = Rsquery.getDate( "MES" );
	if( (dtmp.getYear( )+1900) == anio && dtmp.getDate( )!=15 ){
		str_meses_labels += (str_meses_labels.length()==0?"":",")+dfMonth.format( dtmp ).toUpperCase();
		str_importe_meses_values += (str_importe_meses_values.length()==0?"":",")+Rsquery.getDouble( "INGRESO" );
	}else{
		str_anios_labels += (str_anios_labels.length()==0?"":",")+dfYear.format( dtmp ).toUpperCase();
		str_importe_values += (str_importe_values.length()==0?"":",")+Rsquery.getDouble( "INGRESO" );
	}
	
  %>
      <tr class="<%=rowEven?"rowEven":"rowOdd"%>">
        <td height="20" class="datosReporte"><div align="center"><strong><%=((dtmp.getYear( )+1900) == anio && dtmp.getDate( )!=15?df:dfYear).format( dtmp ).toUpperCase()%></strong></div></td>
        <td height="20" class="datosReporte"><div align="right"><strong><%=nf.format( Rsquery.getDouble( "INGRESO" ) )%>&nbsp;&nbsp;&nbsp;</strong></div></td>
        <td height="20" class="datosReporte"><div align="right"><strong><%=nf.format( Rsquery.getDouble( "ACUMULADO" ) )%>&nbsp;&nbsp;&nbsp;</strong></div></td>
      </tr>
      <%
	  	rowEven = !rowEven;
  }
  %>
    </table></td>
    <td width="50%" align="center"><applet code=com.objectplanet.chart.BarChartApplet archive=/ct/utils/chart.jar width=350 height=250 viewastext>
      <param name=sampleValues value="<%=str_importe_values%>">
      <param name=sampleLabels value="<%=str_importe_values%>">
      <param name=barLabels value="<%=str_anios_labels%>">
      <param name=barLabelsOn value=true>
      <param name=multiColorOn value=true>
      <param name=barLabelStyle value="below_and_floating">
      <param name=rangeAxisLabelAngle value="270">
      <param name=rangeAxisLabelFont value="Arial, normal, 12">
      <param name=background value="white">
    </applet>
      <br></td>
  </tr>
  <tr>
    <td align="center"><applet code=com.objectplanet.chart.BarChartApplet archive=/ct/utils/chart.jar width=350 height=250 viewastext>
      <param name=sampleValues value="<%=str_importe_meses_values%>">
      <param name=sampleLabels value="<%=str_importe_meses_values%>">
      <param name=barLabels value="<%=str_meses_labels%>">
      <param name=charttitle value="<%=anio%>">
      <param name=multiColorOn value=true>
      <param name=barLabelsOn value=true>
      <param name=barLabelAngle value="270">
      <param name=barLabelStyle value="below_and_floating">
      <param name=rangeAxisLabelAngle value="270">
      <param name=rangeAxisLabelFont value="Arial, normal, 12">
      <param name=background value="white">
    </applet></td>
  </tr>
</table>
<br>
<br>
</FORM>
</BODY>
</HTML>
